<?php

namespace Biz\model\springHomeDecActivity;

use Biz\pockets\modelTrait\BizModelTrait;
use Biz\service\springHomeDecActivity\Util;
use Doraemon\pockets\datebase\BaseDbModel;

class ContentTopic extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_brand_activity';

    const _DATABASE_ = 'brand_activity';

    const _TABLE_NAME = 'spring_home_dec_topic';

    const IS_MAIN_YES = 1; //主标题
    const IS_MAIN_NO = 0;  //内容标题

    const IS_TEST_YES = 1; //测试
    const IS_TEST_NO = 0; //默认

    //删除字段名称
    protected static $deleteField = 'data_status';


    use BizModelTrait;


    /**
     * 获取大标题
     * @param $date
     * @return array|mixed
     */
    public static function getMainTopic($date)
    {
        $mainTopic = [
            'topic_id' => '',
            'topic_name' => '',
            'topic_image' => '',
        ];
        $where['is_main'] = self::IS_MAIN_YES;
        $where['is_test'] = Util::isTest();
        $where['data_status'] = self::STATUS_NORMAL;
        $where['show_date'] = $date;
        $result = self::dataSelectInfo($where);
        if ($result && is_array($result)) {
            $mainTopic['topic_id'] = $result['id'];
            $mainTopic['topic_name'] = $result['name'];
            $mainTopic['topic_image'] = $result['image'];
        }
        return $mainTopic;
    }


    /**
     * 获取内容标题
     * @params $mianTopicId
     * @params $date
     * @params $limit
     * @return array
     */
    public static function getContentTopic($mianTopicId,$date,array $limit)
    {
        $contentTopic = [
        ];
        $where['is_main'] = self::IS_MAIN_NO;
        $where['is_test'] = Util::isTest();
        $where['main_topic_id'] = $mianTopicId;
        $where['data_status'] = self::STATUS_NORMAL;
        $where['show_date'] = $date;
        $where['ORDER'] = ['weight' => 'ASC'];
        $where['LIMIT'] = $limit;
        $result = self::dataSelect($where);

        if ($result && is_array($result)) {
            foreach ($result as $item) {
                $contentTopic[] = [
                    'topic_id' => $item['id'],
                    'topic_name' => $item['name'],
                    'topic_image' => $item['image'],
                ];
            }
        }
        return $contentTopic;
    }

    /**
     * 内容主题总数
     * @param $mianTopicId
     * @return int
     */
    public static function topicTotalCount($mianTopicId,$date){
        $where['is_main'] = self::IS_MAIN_NO;
        $where['main_topic_id'] = $mianTopicId;
        $where['data_status'] = self::STATUS_NORMAL;
        $where['show_date'] = $date;
        return self::dataCount($where);
    }
}
